<?php 

class Article{
	private $_db;

	public function __construct($db){
		$this->_db = $db;
	}

	public function create($title, $content, $userId){
		$sql = 'insert into `article` (`title`,`content`,`user_id`,`create_at`) values (:title,:content,:user_id,:created_at)';
		$time = time();
		$userId = (int)$userId;
		$sth = $this->_db->prepare($sql);
		$sth->bindParam(':title',$title);
		$sth->bindParam(':content',$content);
		$sth->bindParam(':user_id',$userId);
		$sth->bindParam(':created_at',$time);
		try{
			if($sth->execute()){
			    return $this->_db->lastInsertId();
			}else{
				throw new Exception("create failed", 1);
			}
		}
		catch(Exception $e){
			return $e->getMessage();
		}
		


	}

	public function edit(){

	}

	public function del(){

	}
}